import 'dart:async';

import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:studymanage/core/sound/ui/remote_player.dart';
import 'package:studymanage/course/course_intro.dart';
import 'package:studymanage/remark/student.dart';
import 'package:studymanage/remark/toRemark.dart';
import 'package:studymanage/util/fun.dart';
import 'package:studymanage/util/request.dart';

class Remark extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return RemarkState();
  }
}

class RemarkState extends State{
  ScrollController _scrollController = ScrollController();
  SwiperController _swiperController =  new SwiperController();


  final List<String> myTabs = <String>[
    '未点评',
    '已点评',
    '学员',
  ];
  int _page =1;
  bool isLoading = false;
  Future<List> bannerList;

  //未点评
  List _remarkList =[] ;

  //已经点评
  List _remarkedList=[] ;
  //学员
  Future<List> _studentList;




  int _currentTab = 0;

  Timer _timer; // 播放计时器


  AudioPlayer audioPlayer = AudioPlayer();

  // 秒格式化为分钟
  String formatTime (int time) {
    if(time==null) return '00:00';
    if(time>3600000) return '59:59';
    var min = (time / 60000).floor().toString();
    var sec = ((time % 60000)/1000).ceil().toString();

    String cacheMin;
    String cacheSec;

    if (min.length == 2) {
      cacheMin = min;
    } else {
      cacheMin = '0' + min;
    }

    if (sec.length == 2) {
      cacheSec = sec;
    } else {
      cacheSec = '0' + sec;
    }

    return cacheMin + '′' + cacheSec;
  }

  @override
  void initState() {
    _scrollController.addListener(() {
      if(_scrollController.position.pixels >
          _scrollController.position.maxScrollExtent-20){
        print('滑动到了最底部');
        if(_currentTab == 0){
          _getNoMark();
        }
        if(_currentTab == 1){
          _getMark();
        }
        if(_currentTab == 2){
          _getStudent();
        }
      }
    });
    bannerList = Request().post<List>("/multiapi/open/c187l_banner",data: {"placeTypeEnum":"2"}).then((response){
       if(response.code == 200){
         return response.data;
       }
       return null;
    });
    super.initState();
    _getNoMark();
  }

  @override
  void dispose() {
    _swiperController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        brightness: Brightness.light,
        title: Text('点评',
          style: TextStyle(
            fontFamily: 'PingFangSC-Medium',
            fontSize: ScreenUtil().setSp(16),
            fontWeight: FontWeight.w600,
            color: Color.fromRGBO(51, 51, 51, 1),
            height: 1,
          ),
        ),
        backgroundColor: Colors.white,
        centerTitle: true,
      ),
      body: RefreshIndicator(
        onRefresh: ()=>_refresh(),
        child: SingleChildScrollView(
          padding: EdgeInsets.only(bottom: 80),
          controller: _scrollController,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              //banner
              Container(
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.width*0.4,
                child: FutureBuilder(
                  future: bannerList,
                  builder: (c,d){
                    if(d.hasData){
                      return Swiper(
                        itemBuilder: (BuildContext context,int index){
                          return Image.network(d.data[index]['bannerImageUrl'],
                            fit: BoxFit.fill,
                          );
                        },
                        itemCount: d.data.length,
                        pagination: SwiperPagination(
                          builder: DotSwiperPaginationBuilder(
                            activeColor: Color.fromRGBO(210, 180, 142, 1),
                            size: ScreenUtil().setHeight(7),
                            activeSize: ScreenUtil().setHeight(7),
                          ),
                        ),
                        autoplay: true,
                        loop: true,
                        duration: 1000,
                        autoplayDelay: 5000,
                        controller: _swiperController,
                        autoplayDisableOnInteraction: true,
                        onTap: (index) {
                          if(d.data[index]['jumpObjectId']!=null){
                            Request().post<Map<String,dynamic>>("/multiapi/c188v_course",data: {"id":d.data[index]['jumpObjectId']}).then((response) {
                              Navigator.push(context, MaterialPageRoute(builder: (context) => CourseIntro(response.data,d.data[index]['jumpObjectId'],null,null)));
                            });
                          }
                          print('选中第' + index.toString() + '个');
                        },
                      );
                    }else{
                      return Center(child: Text("加载中....."),);
                    }
                  },
                ),
              ),
              //中间的标签
              Container(
                width: MediaQuery.of(context).size.width,
                height: ScreenUtil().setHeight(45),
                decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border(
                    bottom: BorderSide(
                      color: Color.fromRGBO(248, 248, 248, 1),
                      width: ScreenUtil().setHeight(7.5),
                    ),
                  ),
                ),
                child: ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: myTabs.length,
                  itemBuilder: (context, index) {
                    return GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      child: Container(
                        width: (MediaQuery.of(context).size.width) / 3,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Container(
                              padding: EdgeInsets.only(
                                top: ScreenUtil().setHeight(16),
                              ),
                              child: Text(
                                myTabs[index],
                                style: TextStyle(
                                  fontFamily: 'PingFangSC-Medium',
                                  fontSize: ScreenUtil().setSp(14),
                                  fontWeight: FontWeight.w600,
                                  color: _currentTab == index
                                      ? Color.fromRGBO(210, 180, 142, 1)
                                      : Color.fromRGBO(51, 51, 51, 1),
                                  height: 1,
                                ),
                              ),
                            ),
                            Offstage(
                              offstage: _currentTab != index,
                              child: Container(
                                width: ScreenUtil().setWidth(20),
                                height: ScreenUtil().setHeight(1.5),
                                color: Color.fromRGBO(210, 180, 142, 1),
                              ),
                            )
                          ],
                        ),
                      ),
                      onTap: () {
                        if(index ==2 ){
                          //学员信息
                          setState(() {
                            _page =1;
                            isLoading = false;
                          });
                          _getStudent();
                        }
                        if(index ==0 ){
                          setState(() {
                            _page =1;
                            isLoading = false;
                            _remarkList = [];
                          });
                          //未点评
                          _getNoMark();
                        }
                        if(index ==1 ){
                          setState(() {
                            _page =1;
                            isLoading = false;
                            _remarkedList=[];
                          });
                          //已经点评
                          _getMark();
                        }
                      },
                    );
                  },
                ),
              ),
              Column(
                children: <Widget>[
                  //未点评
                  Offstage(
                    offstage: _currentTab != 0,
                    child: _remarkList.length>0 ? Container(
                      width: MediaQuery.of(context).size.width,
                      padding: EdgeInsets.only(
                        bottom: ScreenUtil().setHeight(20),
                        left: ScreenUtil().setWidth(12.5),
                        right: ScreenUtil().setWidth(12.5),
                      ),
                      decoration: BoxDecoration(
                      ),
                      child: ListView.builder(
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        itemCount: _remarkList.length,
                        padding: EdgeInsets.all(0),
                        itemBuilder: (context, index) {
                          return Container(
                            margin: EdgeInsets.only(top:10),
                            padding: EdgeInsets.all(15),
                            color: Colors.white,
                            child: Column(
                              children: <Widget>[
                                Container(
                                  padding: EdgeInsets.all(13),
                                  decoration: BoxDecoration(
                                    color: Color(0xffF8F8F8),
                                    borderRadius: BorderRadius.circular(4)
                                  ),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: <Widget>[
                                          Container(
                                            height: 41,
                                            width: 41,
                                            child: CircleAvatar(
                                              backgroundImage: NetworkImage(_remarkList[index]['studentAvatar']),
                                              radius: ScreenUtil().setWidth(20.5),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin: EdgeInsets.only(left: 10),
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  Row(
                                                    children: <Widget>[
                                                      Text(
                                                        _remarkList[index]['studentNickname'],
                                                        style: TextStyle(
                                                          fontFamily: 'PingFangSC-Medium',
                                                          fontSize: ScreenUtil().setSp(14),
                                                          fontWeight: FontWeight.w600,
                                                          color: Color.fromRGBO(51, 51, 51, 1),
                                                          height: 1,
                                                        ),
                                                      ),
                                                      Container(
                                                        width: 50,
                                                        padding: EdgeInsets.all(3),
                                                        margin: EdgeInsets.only(
                                                          left: 3,
                                                        ),
                                                        decoration: BoxDecoration(
                                                          border: Border.all(
                                                            color: Color.fromRGBO(133, 133, 133, 1),
                                                            width: ScreenUtil().setHeight(0.5),
                                                          ),
                                                          borderRadius: BorderRadius.all(
                                                            Radius.circular(ScreenUtil().setHeight(2)),
                                                          ),
                                                        ),
                                                        child: Text(
                                                          _remarkList[index]['className'],
                                                          overflow: TextOverflow.ellipsis,
                                                          style: TextStyle(
                                                            fontFamily: 'PingFangSC-Light',
                                                            fontSize: ScreenUtil().setSp(10),
                                                            fontWeight: FontWeight.w300,
                                                            color: Color.fromRGBO(133, 133, 133, 1),
                                                          ),
                                                        ),
                                                      ),
                                                      Offstage(
                                                        offstage: !_remarkList[index]['boolComplete'],
                                                        child: Container(
                                                          padding: EdgeInsets.all(3),
                                                          margin: EdgeInsets.only(
                                                            left: 3,
                                                          ),
                                                          decoration: BoxDecoration(
                                                            border: Border.all(
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                              width: ScreenUtil().setHeight(0.5),
                                                            ),
                                                            borderRadius: BorderRadius.all(
                                                              Radius.circular(ScreenUtil().setHeight(2)),
                                                            ),
                                                          ),
                                                          child: Text(
                                                            "已经结业",
                                                            style: TextStyle(
                                                              fontFamily: 'PingFangSC-Light',
                                                              fontSize: ScreenUtil().setSp(10),
                                                              fontWeight: FontWeight.w300,
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                            ),
                                                          ),
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                  Container(
                                                    margin: EdgeInsets.only(top: 5),
                                                    child: Row(
                                                      children: <Widget>[
                                                        Container(
                                                          child: Text(
                                                            _remarkList[index]['shareDateCN'],
                                                            style: TextStyle(
                                                              fontFamily: 'PingFangSC-Light',
                                                              fontSize: ScreenUtil().setSp(11),
                                                              fontWeight: FontWeight.w300,
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                              height: 1,
                                                            ),
                                                          ),
                                                        ),
                                                        Offstage(
                                                          offstage: _remarkList[index]["shareRecordContentVoice"]=="",
                                                          child: RemotePlayer(_remarkList[index]['shareRecordContentVoice'],2),
                                                        )
                                                      ],
                                                    ),
                                                  )
                                                ],
                                              ),
                                            ),
                                          ),
                                          Container(
                                            width: 42,
                                            height: 23,
                                            decoration: BoxDecoration(
                                                color: Color.fromRGBO(214, 178, 128, 1),
                                                borderRadius: BorderRadius.circular(2)
                                            ),
                                            child: FlatButton(
                                              padding: EdgeInsets.all(0),
                                              child: Text(
                                                '点评',
                                                style: TextStyle(
                                                  fontFamily: 'PingFangSC-Regular',
                                                  fontSize: ScreenUtil().setSp(12),
                                                  color: Colors.white,
                                                ),
                                              ),
                                              onPressed: () {
                                                Navigator.push(context, MaterialPageRoute(builder: (context) => ToRemark(_remarkList[index],()=>_update())));
                                              },
                                            ),
                                          ),
                                        ],
                                      ),
                                      Container(
                                        margin: EdgeInsets.only(left: 51,top: 10),
                                        child: Text(_remarkList[index]['shareRecordContent']!=null ?_remarkList[index]['shareRecordContent'] : ""),
                                      )

                                    ],
                                  ),
                                )
                              ],
                            ),
                          );
                        },
                      ),
                    ): Center(
                      child: Text("暂无"),
                    )
                  ),
                  //已点评

                  Offstage(
                    offstage:  _currentTab != 1,
                    child: _remarkedList.length >0 ? Container(
                      width: MediaQuery.of(context).size.width,
                      color: Color(0xffF8F8F8),
                      padding: EdgeInsets.only(
                        bottom: ScreenUtil().setHeight(20),
                        left: ScreenUtil().setWidth(12.5),
                        right: ScreenUtil().setWidth(12.5),
                      ),
                      child: ListView.builder(
                        padding: EdgeInsets.all(0),
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        itemCount: _remarkedList.length,
                        itemBuilder: (context, index) {
                          return Container(
                            margin: EdgeInsets.only(top:10),
                            padding: EdgeInsets.all(15),
                            color: Colors.white,
                            child: Column(
                              children: <Widget>[
                                Container(
                                  padding: EdgeInsets.all(13),
                                  decoration: BoxDecoration(
                                      color: Color(0xffF8F8F8),
                                      borderRadius: BorderRadius.circular(4)
                                  ),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: <Widget>[
                                          Container(
                                            height: 41,
                                            width: 41,
                                            child: CircleAvatar(
                                              backgroundImage: NetworkImage(_remarkedList[index]['studentAvatar']),
                                              radius: ScreenUtil().setWidth(20.5),
                                            ),
                                          ),
                                          Expanded(
                                            child: Container(
                                              margin: EdgeInsets.only(left: 10),
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  Row(
                                                    children: <Widget>[
                                                      Text(
                                                        _remarkedList[index]['studentNickname'],
                                                        style: TextStyle(
                                                          fontFamily: 'PingFangSC-Medium',
                                                          fontSize: ScreenUtil().setSp(14),
                                                          fontWeight: FontWeight.w600,
                                                          color: Color.fromRGBO(51, 51, 51, 1),
                                                          height: 1,
                                                        ),
                                                      ),
                                                      Container(
                                                        width: 50,
                                                        padding: EdgeInsets.all(3),
                                                        margin: EdgeInsets.only(
                                                          left: ScreenUtil().setWidth(9.5),
                                                        ),
                                                        decoration: BoxDecoration(
                                                          border: Border.all(
                                                            color: Color.fromRGBO(133, 133, 133, 1),
                                                            width: ScreenUtil().setHeight(0.5),
                                                          ),
                                                          borderRadius: BorderRadius.all(
                                                            Radius.circular(ScreenUtil().setHeight(2)),
                                                          ),
                                                        ),
                                                        child: Text(
                                                          _remarkedList[index]['className'],
                                                          overflow: TextOverflow.ellipsis,
                                                          style: TextStyle(
                                                            fontFamily: 'PingFangSC-Light',
                                                            fontSize: ScreenUtil().setSp(10),
                                                            fontWeight: FontWeight.w300,
                                                            color: Color.fromRGBO(133, 133, 133, 1),
                                                          ),
                                                        ),
                                                      ),
                                                      Offstage(
                                                        offstage: !_remarkedList[index]['boolComplete'],
                                                        child: Container(
                                                          padding: EdgeInsets.all(3),
                                                          margin: EdgeInsets.only(
                                                            left: 3,
                                                          ),
                                                          decoration: BoxDecoration(
                                                            border: Border.all(
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                              width: ScreenUtil().setHeight(0.5),
                                                            ),
                                                            borderRadius: BorderRadius.all(
                                                              Radius.circular(ScreenUtil().setHeight(2)),
                                                            ),
                                                          ),
                                                          child: Text(
                                                            "已经结业",
                                                            style: TextStyle(
                                                              fontFamily: 'PingFangSC-Light',
                                                              fontSize: ScreenUtil().setSp(10),
                                                              fontWeight: FontWeight.w300,
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                            ),
                                                          ),
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                  Container(
                                                    margin: EdgeInsets.only(top: 5),
                                                    child: Row(
                                                      children: <Widget>[
                                                        Container(
                                                          child: Text(
                                                            _remarkedList[index]['shareDateCN'],
                                                            style: TextStyle(
                                                              fontFamily: 'PingFangSC-Light',
                                                              fontSize: ScreenUtil().setSp(11),
                                                              fontWeight: FontWeight.w300,
                                                              color: Color.fromRGBO(133, 133, 133, 1),
                                                              height: 1,
                                                            ),
                                                          ),
                                                        ),
                                                        GestureDetector(
                                                          child: Container(
                                                              margin: EdgeInsets.only(left: 8),
                                                              child: Image.asset("assets/images/mine/ydp_bfanky.png")
                                                          ),
                                                          onTap: (){
                                                            audioPlayer.play(_remarkedList[index]['shareRecordContentVoice']);
                                                          },
                                                        )
                                                      ],
                                                    ),
                                                  )
                                                ],
                                              ),
                                            ),
                                          )],
                                      ),
                                      Container(
                                        margin: EdgeInsets.only(left: 51,top: 10),
                                        child: Text(_remarkedList[index]['shareRecordContent']!=null?_remarkedList[index]['shareRecordContent']:""),
                                      )

                                    ],
                                  ),
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: 23),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.end,
                                    children: <Widget>[
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment.end,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: <Widget>[
                                          Column(
                                            crossAxisAlignment: CrossAxisAlignment.end,
                                            children: <Widget>[
                                              Row(
                                                crossAxisAlignment: CrossAxisAlignment.center,
                                                children: <Widget>[
                                                  Container(
                                                    padding: EdgeInsets.only(
                                                      left: ScreenUtil().setWidth(4.5),
                                                      right: ScreenUtil().setWidth(4.5),
                                                      top: ScreenUtil().setHeight(3.5),
                                                      bottom: ScreenUtil().setHeight(3.5),
                                                    ),
                                                    margin: EdgeInsets.only(
                                                      right: ScreenUtil().setWidth(9.5),
                                                    ),
                                                    decoration: BoxDecoration(
                                                      border: Border.all(
                                                        color: Color.fromRGBO(133, 133, 133, 1),
                                                        width: ScreenUtil().setHeight(0.5),
                                                      ),
                                                      borderRadius: BorderRadius.all(
                                                        Radius.circular(ScreenUtil().setHeight(2)),
                                                      ),
                                                    ),
                                                    child: Text(
                                                      '情感导师点评',
                                                      style: TextStyle(
                                                        fontFamily: 'PingFangSC-Light',
                                                        fontSize: ScreenUtil().setSp(10),
                                                        fontWeight: FontWeight.w300,
                                                        color: Color.fromRGBO(133, 133, 133, 1),
                                                      ),
                                                    ),
                                                  ),
                                                  Text(
                                                    _remarkedList[index]['teacherNickname']!=null ? _remarkedList[index]['teacherNickname'] : "" ,
                                                    style: TextStyle(
                                                      fontFamily: 'PingFangSC-Medium',
                                                      fontSize: ScreenUtil().setSp(14),
                                                      fontWeight: FontWeight.w600,
                                                      color: Color.fromRGBO(51, 51, 51, 1),
                                                      height: 1,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              Container(
                                                margin: EdgeInsets.only(top: 5),
                                                child: Row(
                                                  children: <Widget>[
                                                    Container(
                                                      margin: EdgeInsets.only(right: 8),
                                                      child: Text(
                                                        _remarkedList[index]['commentDateCN']!=null?_remarkedList[index]['commentDateCN']:"",
                                                        style: TextStyle(
                                                          fontFamily: 'PingFangSC-Light',
                                                          fontSize: ScreenUtil().setSp(11),
                                                          fontWeight: FontWeight.w300,
                                                          color: Color.fromRGBO(133, 133, 133, 1),
                                                          height: 1,
                                                        ),
                                                      ),
                                                    ),
                                                    Offstage(
                                                      offstage: !_remarkedList[index].containsKey("teacherContentVoice")||_remarkedList[index]["teacherVoiceAudioDuration"]==0,
                                                      child: GestureDetector(
                                                        child: Image.asset("assets/images/mine/ydp_bfanky.png"),
                                                        onTap: (){
                                                          audioPlayer.play(_remarkedList[index]['teacherContentVoice']);
                                                        },
                                                      ),
                                                    )
                                                  ],
                                                ),
                                              )
                                            ],
                                          ),
                                          Container(
                                            height: 41,
                                            width: 41,
                                            margin: EdgeInsets.only(left: 10),
                                            child: CircleAvatar(
                                              backgroundImage: NetworkImage(_remarkedList[index]['teacherAvatar']!=null?_remarkedList[index]['teacherAvatar']:""),
                                              radius: ScreenUtil().setWidth(20.5),
                                            ),
                                          ),
                                        ],
                                      ),
                                      Container(
                                        margin: EdgeInsets.only(right: 51,top: 10,left: 51),
                                        alignment: Alignment.topRight,
                                        child: Column(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Column(
                                              crossAxisAlignment: CrossAxisAlignment.end,
                                              children: <Widget>[
                                                Text(_remarkedList[index]['teacherContent']!=null?_remarkedList[index]['teacherContent']:""),
                                                Container(
                                                  height: 0,
                                                  child: Text(_remarkedList[index]['taskTitle'],style: TextStyle(fontSize: ScreenUtil().setSp(11),),)
                                                ),

                                              ],
                                            ),
                                            Container(
                                              decoration: BoxDecoration(
                                                  border: Border.all(
                                                    color: Color.fromRGBO(133, 133, 133, 1),
                                                    width: ScreenUtil().setHeight(0.5),
                                                  ),
                                                  borderRadius: BorderRadius.circular(2)
                                              ),
                                              margin: EdgeInsets.only(top: 10),
                                              padding: EdgeInsets.all(3),
                                              child: Text(
                                                _remarkedList[index]['taskTitle'],
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                  fontFamily: 'PingFangSC-Regular',
                                                  fontSize: ScreenUtil().setSp(11),
                                                  color: Color.fromRGBO(133, 133, 133, 1),
                                                ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),

                                    ],
                                  ),
                                ),
                              ],
                            ),
                          );
                        },
                      ),
                    ) : Center(child: Text("暂无"),),
                  ),

                  //学员
                  Offstage(
                    offstage: _currentTab != 2,
                    child: FutureBuilder(
                      future: _studentList,
                      builder: (context,snap){
                        if(snap.hasData){
                          return Container(
                            width: MediaQuery.of(context).size.width,
                            padding: EdgeInsets.only(
                              top: ScreenUtil().setHeight(6.5),
                              bottom: ScreenUtil().setHeight(80),
                              left: ScreenUtil().setWidth(12.5),
                              right: ScreenUtil().setWidth(12.5),
                            ),
                            child: ListView.builder(
                              shrinkWrap: true,
                              physics: NeverScrollableScrollPhysics(),
                              itemCount: snap.data.length,
                              itemBuilder: (context, index) {
                                return Container(
                                  padding: EdgeInsets.only(
                                    top: ScreenUtil().setHeight(14),
                                  ),
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: <Widget>[
                                      GestureDetector(
                                        child: CircleAvatar(
                                          backgroundImage: NetworkImage(snap.data[index]['studentAvatar']!=null?snap.data[index]['studentAvatar']:""),
                                          radius: ScreenUtil().setWidth(20.5),
                                        ),
                                        onTap: () {
                                          Navigator.push(context, MaterialPageRoute(builder: (context) => Student(snap.data[index])));
                                        },
                                      ),
                                      Container(
                                        margin: EdgeInsets.only(
                                          left: ScreenUtil().setHeight(11),
                                        ),
                                        padding: EdgeInsets.only(
                                          top: ScreenUtil().setHeight(5.5),
                                          bottom: ScreenUtil().setHeight(19.5),
                                        ),
                                        decoration: BoxDecoration(
                                          border: Border(
                                            bottom: BorderSide(
                                              width: ScreenUtil().setHeight(0.5),
                                              color: Color.fromRGBO(238, 238, 238, 1),
                                            ),
                                          ),
                                        ),
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: <Widget>[
                                            GestureDetector(
                                              child: Row(
                                                children: <Widget>[
                                                  Text(
                                                    snap.data[index]['studentNickname']!=null?snap.data[index]['studentNickname']:"",
                                                    style: TextStyle(
                                                      fontFamily: 'PingFangSC-Medium',
                                                      fontSize: ScreenUtil().setSp(14),
                                                      fontWeight: FontWeight.w600,
                                                      color: Color.fromRGBO(51, 51, 51, 1),
                                                      height: 1,
                                                    ),
                                                  ),
                                                  Offstage(
                                                    offstage: snap.data[index]['className']==null,
                                                    child: Container(
                                                      padding: EdgeInsets.only(
                                                        left: ScreenUtil().setWidth(4.5),
                                                        right: ScreenUtil().setWidth(4.5),
                                                        top: ScreenUtil().setHeight(3.5),
                                                        bottom: ScreenUtil().setHeight(3.5),
                                                      ),
                                                      margin: EdgeInsets.only(
                                                        left: ScreenUtil().setWidth(9.5),
                                                      ),
                                                      decoration: BoxDecoration(
                                                        border: Border.all(
                                                          color: Color.fromRGBO(133, 133, 133, 1),
                                                          width: ScreenUtil().setHeight(0.5),
                                                        ),
                                                        borderRadius: BorderRadius.all(
                                                          Radius.circular(ScreenUtil().setHeight(2)),
                                                        ),
                                                      ),
                                                      child: Text(
                                                        snap.data[index]['className']??"",
                                                        style: TextStyle(
                                                          fontFamily: 'PingFangSC-Light',
                                                          fontSize: ScreenUtil().setSp(10),
                                                          fontWeight: FontWeight.w300,
                                                          color: Color.fromRGBO(133, 133, 133, 1),
                                                        ),
                                                      ),
                                                    ),
                                                  )
                                                ],
                                              ),
                                              onTap: () {
                                                Navigator.push(context, MaterialPageRoute(builder: (context) => Student(snap.data[index])));
                                              },
                                            ),
                                            Container(
                                              width: MediaQuery.of(context).size.width - ScreenUtil().setWidth(80),
                                              margin: EdgeInsets.only(
                                                top: ScreenUtil().setHeight(10),
                                              ),
                                              child: Text(
                                                snap.data[index]['studentIntro']!=null ? snap.data[index]['studentIntro'] : "",
                                                style: TextStyle(
                                                  fontFamily: 'PingFangSC-Light',
                                                  fontSize: ScreenUtil().setSp(13),
                                                  fontWeight: FontWeight.w300,
                                                  color: Color.fromRGBO(51, 51, 51, 1),
                                                ),
                                                textAlign: TextAlign.justify,
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                );
                              },
                            ),
                          );
                        }else{
                          return Center(child: Text("暂无"),);
                        }
                      }
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
  _getNoMark() {
    if(isLoading){
      return;
    }
    if(_timer!=null){
      _timer.cancel();
      _timer = null;
    }
    setState(() {
      isLoading = true;
    });
    Request().post<Map<String, dynamic>>("/multiapi/c197p_studyRecord",
        data: {
          "pageNum": _page,
          "pageSize": 10,
          "commentStateEnum": 1
        }).then((response){
      response.data['list'].forEach((element) {
        element['isPlayAudio'] = false;
        element['initSchedule'] = 0;
        element['currentSchedule'] = 0.0;
      });
        setState(() {
          if(!response.data["isLastPage"]){
            isLoading =false;
          }
          _currentTab = 0;
          _page+=1;
          _remarkList.addAll(response.data['list']) ;
        });
    });
  }
  _getMark(){
    if(isLoading){
      return;
    }
    setState(() {
      isLoading = true;
    });
    if(_timer!=null){
      _timer.cancel();
      _timer = null;
    }
    Request().post<Map<String, dynamic>>("/multiapi/c197p_studyRecord",
        data: {
          "pageNum": _page,
          "pageSize": 10,
          "commentStateEnum": 2
        }).then((response){
      response.data['list'].forEach((element) {
        element['isPlayAudio'] = false;
        element['initSchedule'] = 0;
        element['currentSchedule'] = 0.0;
        element['teacherIsPlayAudio'] = false;
        element['teacherInitSchedule'] = 0;
        element['teacherCurrentSchedule'] = 0.0;
      });
      setState(() {
        if(!response.data["isLastPage"]){
          isLoading =false;
        }
        _currentTab = 1;
        _page+=1;
        _remarkedList.addAll(response.data['list']);
      });

    });
  }
  _getStudent(){
    if(isLoading){
      return;
    }
    setState(() {
      isLoading = true;
    });
    _studentList = Request().post<Map<String, dynamic>>("/multiapi/c198p_student",
        data: {
          "pageNum": _page,
          "pageSize": 10
        }).then((response){
      setState(() {
        if(!response.data["isLastPage"]){
          isLoading =false;
        }
        _page+=1;
        _currentTab = 2;
      });
      return response.data['list'];
    });
  }
  Future<Null> _refresh () async{
    setState(() {
      _page =1;
      isLoading = false;
    });
    if(_currentTab == 0){
      _getNoMark();
    }
    if(_currentTab == 1){
      _getMark();
    }
    if(_currentTab == 2){
      _getStudent();
    }
    return null;
  }


  _update() {
    setState(() {
      _page =1;
      isLoading = false;
      _remarkList=[];
      _remarkedList=[];
    });
    _getNoMark();
    _getMark();
  }
}

